package cn.semes.basic.controller;

import cn.semes.basic.domain.GetEmailCodeDto;
import cn.semes.basic.domain.GetPhoneCodeDto;
import cn.semes.basic.service.IVerifyCodeService;
import cn.semes.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService iVerifyCodeService;

// 发送验证图片
    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult graph(@PathVariable String imageCodeKey) throws IOException {
        String base64Img =iVerifyCodeService.graph(imageCodeKey);
return AjaxResult.me().success(base64Img);
    }

// 前端点击手机注册获取
    @PostMapping("/smsCode")
    public AjaxResult getPhoneCode(@RequestBody GetPhoneCodeDto dto) {
           iVerifyCodeService.GetCode(dto);
           return AjaxResult.me().success();
    }

    // 前端点击邮箱注册获取
    @PostMapping("/emailCode")
    public AjaxResult getEmailCode(@RequestBody GetEmailCodeDto dto) {
        iVerifyCodeService.getEmailCode(dto);
        return AjaxResult.me().success();
    }
}
